package com.ds.dsm.nav;

import com.ds.common.util.StringUtility;
import com.ds.config.TreeListResultModel;
import com.ds.dsm.admin.temp.JavaTempNavTree;
import com.ds.dsm.website.DomainTempNavTree;
import com.ds.enums.db.MethodChinaName;
import com.ds.esd.custom.annotation.TreeViewAnnotation;
import com.ds.esd.custom.api.annotation.APIEventAnnotation;
import com.ds.esd.custom.layout.annotation.LayoutAnnotation;
import com.ds.esd.custom.module.annotation.ModuleAnnotation;
import com.ds.esd.custom.nav.annotation.NavGalleryAnnotation;
import com.ds.esd.custom.nav.annotation.TabsAnnotation;
import com.ds.esd.dsm.enums.DSMType;
import com.ds.esd.util.TreePageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/dsm/nav/")
@NavGalleryAnnotation()
@LayoutAnnotation(transparent = false)
@TabsAnnotation(closeBtn = true)
public class DSMNavTree {


    @RequestMapping(method = RequestMethod.POST, value = "WebSiteTreeNav")
    @APIEventAnnotation(autoRun = true)
    @TreeViewAnnotation
    @ModuleAnnotation(imageClass = "spafont spa-icon-c-cssbox", dynLoad = true, caption = "常用模板")
    @ResponseBody
    public TreeListResultModel<List<DomainTempNavTree>> getDSMTempTreeNav(String id) {
        TreeListResultModel<List<DomainTempNavTree>> resultModel = new TreeListResultModel<List<DomainTempNavTree>>();
        DomainTempNavTree viewItem = new DomainTempNavTree("dsm.website.WebSiteList", null);
        List<DomainTempNavTree> items = new ArrayList<>();
        items.add(viewItem);
        if (id != null && !id.equals("")) {
            String[] orgIdArr = StringUtility.split(id, ";");
            resultModel.setIds(Arrays.asList(orgIdArr));
        } else {
            resultModel.setIds(Arrays.asList(new String[]{viewItem.getFristClassItem(viewItem).getId()}));
        }
        resultModel.setData(items);
        return resultModel;

    }


    @MethodChinaName(cname = "代码模板")
    @RequestMapping(method = RequestMethod.POST, value = "CodeTemps")
    @APIEventAnnotation(autoRun = true)
    @TreeViewAnnotation
    @ModuleAnnotation(imageClass = "spafont spa-icon-settingprj", dynLoad = true, caption = "代码模板")
    @ResponseBody
    public TreeListResultModel<List<JavaTempNavTree>> getTempManager(String id) {
        TreeListResultModel<List<JavaTempNavTree>> resultModel = new TreeListResultModel<List<JavaTempNavTree>>();
        resultModel = TreePageUtil.getTreeList(Arrays.asList(DSMType.values()), JavaTempNavTree.class);
        return resultModel;

    }

    @RequestMapping(method = RequestMethod.POST, value = "ViewTemps")
    @APIEventAnnotation(autoRun = true)
    @TreeViewAnnotation
    @ModuleAnnotation(imageClass = "spafont spa-icon-config", dynLoad = true, caption = "视图配置")
    @ResponseBody
    public TreeListResultModel<List<JavaTempNavTree>> getViewTemps(String id) {
        TreeListResultModel<List<JavaTempNavTree>> resultModel = new TreeListResultModel<List<JavaTempNavTree>>();
        resultModel = TreePageUtil.getTreeList(Arrays.asList(DSMType.aggregation), JavaTempNavTree.class);

        return resultModel;

    }


}
